// pages/articleDetail/index.js
const {
  post
} = getApp();
Page({
  data: {
    data: {
      title: "",
      content: "",
      create_time: 0,
      showPage:false
    }
  },
  // 初始化加载
  onLoad: function (e) {
    post("/spread/article/detail", {
      article_id: e.id
    }).then(res => {
      if (res.result == 1) {
        res.data.content = res.data.content.replace(/width\s*:\s*[0-9]+px/g, 'width:100%');
        res.data.content = res.data.content.replace(/<([\/]?)(center)((:?\s*)(:?[^>]*)(:?\s*))>/g, '<$1div$3>');
        res.data.content = res.data.content.replace(/\<img/gi, '<img class="rich-img" ');
        res.data.content = res.data.content.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="width:100%;height:auto;display: block;margin:auto"');
        res.data.content = res.data.content.replace(/\<p/gi, '<P class="rich-p" style="word-break: break-all;white-space: pre-warp;"');
        this.setData({
          "data": res.data,
          "data.content": res.data.content,
          "showPage":true
        })
      }
    });
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    })
  },
  onShow: function () {
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    });
  }
})